package com.cloud.common.base.dto;

import com.cloud.common.constant.CommonConstant;

import javax.validation.constraints.NotNull;

/**
 * 分页DTO
 *
 * @author wangjian
 * @version 1.0.0.RELEASES
 * @create 2021年03月16日 3/16/21
 * @since JDK 1.8
 * Life is so short,do something to make yourself happy,such as coding
 */
public class PageDTO extends CommonDTO {

    /**
     * serialVersionUID,非版本变更，否则不可随意变更
     */
    private static final long serialVersionUID = -1168549072907740906L;

    @NotNull(message = "页码不能为空")
    private Long current = CommonConstant.DEFAULT_PAGE;

    @NotNull(message = "行数不能为空")
    private Long size = CommonConstant.DEFAULT_LIMIT;

    public void setPage(long page) {
        if (page <= 0) {
            this.current = CommonConstant.DEFAULT_PAGE;
        } else {
            this.current = page;
        }
    }

    public void setLimit(long limit) {
        if (limit <= 0) {
            this.size = CommonConstant.DEFAULT_LIMIT;
        } else if (this.size >= CommonConstant.MAX_LIMIT) {
            this.size = CommonConstant.MAX_LIMIT;
        } else {
            this.size = limit;
        }
    }

    public PageDTO() {
    }

    @Override
    public String toString() {
        return "PageDTO{" +
                "current=" + current +
                ", size=" + size +
                '}';
    }

    public Long getCurrent() {
        return current;
    }

    public void setCurrent(Long current) {
        this.current = current;
    }

    public Long getSize() {
        return size;
    }

    public void setSize(Long size) {
        this.size = size;
    }
}
